package D666;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class Denglu {
    public static void main(String[] args) throws SQLException,ClassNotFoundException{
        Connection  connection = SqlConnection.getCon();
        Scanner  username = new Scanner(System.in);
        System.out.println("请输入用户名");
        Scanner  password = new Scanner(System.in);
        System.out.println("请输入密码");
        Scanner scanner = new Scanner(System.in);
        String  sql = "select * from users where username = ? and password = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,username.next());
        preparedStatement.setString(2,password.next());
        ResultSet  resultSet = preparedStatement.executeQuery();
        if (resultSet.next()){
            String name = resultSet.getString("username");
            String pwd = resultSet.getString("password");
            System.out.println("用户名："+name);
            System.out.println("密码："+pwd);
            System.out.println("登录成功");
        }
        else {
            System.out.println("登录失败");
        }
    }
}
